package com.panasonic.web.vo;

import com.alibaba.excel.annotation.ExcelProperty;

import com.panasonic.common.utils.DateUtils;
import com.panasonic.web.domain.cms.CmsPermission;
import com.panasonic.web.domain.cms.CmsUser;
import com.panasonic.web.util.CmsSecurityUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @className: CmsUserImportVo
 * @description: TODO 类描述
 * @author: laiweifeng
 * @date: 2021/11/21
 **/
@Data
public class CmsUserImportVo {

    @ExcelProperty("用户名")
    private String username;
    @ExcelProperty("用户密码")
    private String password;
    @ExcelProperty("找回密码邮箱")
    private String email;

    public CmsUser toCmsUser(String[] strings, Integer type, Integer pan, Long panId) {
        CmsUser user = new CmsUser();
        user.setPasswordCache(password);
        user.setPassword(CmsSecurityUtils.encryptPassword(password));
        user.setEmail(email);
        user.setUsername(username);
        user.setRemark("批量导入");
        user.setStatus("0");
        user.setCreateBy(CmsSecurityUtils.getUsername());
        user.setCreateTime(DateUtils.getNowDate());
        user.setType(Optional.ofNullable(type).orElse(1));
        user.setPanId(Optional.ofNullable(panId).orElse(0L));
        user.setPan(Optional.ofNullable(pan).orElse(1));
        List<CmsPermission> cmsPermissionList = new ArrayList<>();
        Arrays.stream(strings).forEach(s -> {
            CmsPermission permission = new CmsPermission();
            permission.setCategoryId(Long.valueOf(s));
            cmsPermissionList.add(permission);
        });
        user.setCmsPermissionList(cmsPermissionList);
        return user;
    }
}
